package shuaige.jdk.stream.collectors相关的方法.汇总和统计相关;

import java.util.*;
import java.util.stream.Collectors;

public class SummarizingXxx高级汇总 {
    static List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9);

    public static void main(String[] args) {
        summarizingLong();
    }

    public static void summarizingLong() {
        IntSummaryStatistics intSummary = list.stream().collect(Collectors.summarizingInt(value -> value));
        System.out.println(intSummary);
        System.out.println("总数：" + intSummary.getCount());
        System.out.println("总和：" + intSummary.getSum());
        System.out.println("最小：" + intSummary.getMin());
        System.out.println("平均值：" + intSummary.getAverage());
        System.out.println("最大值：" + intSummary.getMax());
    }

    public static void summarizingDouble() {
        LongSummaryStatistics longSummary = list.stream().collect(Collectors.summarizingLong(value -> value));
        System.out.println(longSummary);
        System.out.println("总数：" + longSummary.getCount());
        System.out.println("总和：" + longSummary.getSum());
        System.out.println("最小：" + longSummary.getMin());
        System.out.println("平均值：" + longSummary.getAverage());
        System.out.println("最大值：" + longSummary.getMax());
    }

    public static void summarizingInt() {
        DoubleSummaryStatistics doubleSummary = list.stream().collect(Collectors.summarizingDouble(value -> value));
        System.out.println(doubleSummary);
        System.out.println("总数：" + doubleSummary.getCount());
        System.out.println("总和：" + doubleSummary.getSum());
        System.out.println("最小：" + doubleSummary.getMin());
        System.out.println("平均值：" + doubleSummary.getAverage());
        System.out.println("最大值：" + doubleSummary.getMax());
    }

}
